package com.ydd.controller.admin;

import com.ydd.dto.CatePageDTO;
import com.ydd.entity.YddCate;
import com.ydd.result.PageResult;
import com.ydd.result.Result;
import com.ydd.service.CateService;
import com.ydd.vo.CateVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/ydd_cate")
@Slf4j
@Api(tags = "分类管理接口")
public class CateController {
    @Lazy
    @Autowired
    private CateService cateService;


    /**
     * 分类详情
     * @param id
     * @return
     */
    @GetMapping("/rowInfo")
    @ApiOperation("分类详情")
    public Result<CateVO> rowInfo(Long id){
        CateVO cateVO = cateService.rowInfo(id);
        return Result.success(cateVO);
    }

    /**
     * 分页查询
     * @return
     */
    @GetMapping("/list")
    @ApiOperation("分页分类查询")
    public Result<PageResult> pageList(CatePageDTO catePageDTO){
        log.info("分页数据：{}",catePageDTO);
        PageResult pageResult=cateService.pageList(catePageDTO);
        return Result.success(pageResult);
    }

    /**
     * 根据分类id删除
     * @param id
     * @return
     */
    @GetMapping("/del")
    @ApiOperation("根据分类id删除")
    public Result deleteById(Integer id){
        cateService.deleteById(id);
        return Result.success();
    }

    /**
     * 修改分类信息
     * @param yddCate
     * @return
     */
    @PostMapping("/update")
    @ApiOperation("修改分类信息")
    public Result update(@RequestBody YddCate yddCate){
        cateService.update(yddCate);
        return Result.success();
    }

    /**
     * 增加分类信息
     * @param yddCate
     * @return
     */
    @PostMapping("/add")
    @ApiOperation("增加分类信息")
    public Result add(@RequestBody YddCate yddCate){
        cateService.add(yddCate);
        return Result.success();
    }

    /**
     * 查询所有分类列表
     * @return
     */
    @GetMapping("/all")
    @ApiOperation("获取分类列表")
    public Result<YddCate[]> cateAll(){
        YddCate[] yddCateList = cateService.cateAll();
        return Result.success(yddCateList);
    }
}
